  /* 326 */
  /***/
  (function(module, exports, __webpack_require__) {

    "use strict";


    Object.defineProperty(exports, "__esModule", {
      value: true
    });

    var _toConsumableArray2 = __webpack_require__(8);

    var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

    var _getPrototypeOf = __webpack_require__(3);

    var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

    var _classCallCheck2 = __webpack_require__(0);

    var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

    var _createClass2 = __webpack_require__(1);

    var _createClass3 = _interopRequireDefault(_createClass2);

    var _possibleConstructorReturn2 = __webpack_require__(4);

    var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

    var _inherits2 = __webpack_require__(5);

    var _inherits3 = _interopRequireDefault(_inherits2);

    var _mobx = __webpack_require__(2);

    var _bind = __webpack_require__(10);

    var _bind2 = _interopRequireDefault(_bind);

    var _XbsjCzmObj2 = __webpack_require__(11);

    var _XbsjCzmObj3 = _interopRequireDefault(_XbsjCzmObj2);

    var _XbsjObject = __webpack_require__(9);

    var _XbsjObject2 = _interopRequireDefault(_XbsjObject);

    var _createGroundRectangle = __webpack_require__(81);

    var _createGroundRectangle2 = _interopRequireDefault(_createGroundRectangle);

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : {
        default: obj
      };
    }

    var defaultOptions = {
      position: [0, 0, 0],
      origin: [0.5, 0.5],
      rotation: 0,
      width: 1000,
      height: 1000,
      canvasWidth: 512,
      canvasHeight: 512,
      show: true,
      color: [1, 1, 1, 1],
      imageUrl: ''
    };

    /**
     * 自定义贴地矩形
     * @memberof Obj
     * @class
     * @extends XbsjCzmObj
     */

    var CustomGroundRectangle = function(_XbsjCzmObj) {
      (0, _inherits3.default)(CustomGroundRectangle, _XbsjCzmObj);

      function CustomGroundRectangle(earth, guid) {
        (0, _classCallCheck3.default)(this, CustomGroundRectangle);

        var _this = (0, _possibleConstructorReturn3.default)(this, (CustomGroundRectangle.__proto__ || (0,
          _getPrototypeOf2.default)(CustomGroundRectangle)).call(this, earth, guid));

        _this.disposers.push((0, _bind2.default)(_this, 'enabled', _this, 'show'));
        // this.disposers.push(registerPositionEditing(this._earth, this));                
        // this.disposers.push(registerRotationEditing(this._earth, this));      

        (0, _mobx.extendObservable)(_this, {
          _texture: undefined,
          _groundPrimitive: undefined
        }, {
          _texture: _mobx.observable.ref,
          _groundPrimitive: _mobx.observable.ref
        });

        _this.disposers.push(function() {
          if (_this._groundPrimitive) {
            earth.czm.scene.groundPrimitives.remove(_this._groundPrimitive);
            _this._groundPrimitive = undefined;
          }
          if (_this._texture) {
            _this._texture = _this._texture && _this._texture.destroy();
          }
        });

        var updateTexture = function updateTexture() {
          _this._texture = _this._texture && _this._texture.destroy();
          var texture = new Cesium.Texture({
            context: earth.czm.scene.context,
            width: _this.canvasWidth,
            height: _this.canvasHeight,
            flipY: true
          });

          _this._texture = texture;
        };
        updateTexture();
        _this.disposers.push((0, _mobx.reaction)(function() {
          return {
            width: _this.canvasWidth,
            height: _this.canvasHeight
          };
        }, updateTexture));

        // texture变了，需要重新赋值
        var updateTexture2 = function updateTexture2() {
          var texture = _this._texture;
          _this._groundPrimitive && (_this._groundPrimitive.appearance.material.uniforms.image = texture);
        };
        updateTexture2();
        _this.disposers.push((0, _mobx.reaction)(function() {
          return {
            _texture: _this._texture
          };
        }, updateTexture2));

        var updateCanvas = function updateCanvas() {
          if (!_this._canvas) {
            var canvas = document.createElement('canvas');
            _this._canvas = canvas;
            _this._ctx = canvas.getContext('2d');
          }

          _this._canvas.width = _this.canvasWidth;
          _this._canvas.height = _this.canvasHeight;
        };
        updateCanvas();
        _this.disposers.push((0, _mobx.reaction)(function() {
          return {
            canvasWidth: _this.canvasWidth,
            canvasHeight: _this.canvasHeight
          };
        }, updateCanvas));

        _this._scratchColor = new Cesium.Color();
        var updateGroundPrimitive = function updateGroundPrimitive() {
          if (_this._groundPrimitive) {
            earth.czm.scene.groundPrimitives.remove(_this._groundPrimitive);
            _this._groundPrimitive = undefined;
          }

          var classificationType = Cesium.ClassificationType.BOTH;
          // const minHeight = 0;
          // const maxHeight = 0;
          var image = undefined;
          var color = undefined;
          // const groundPrimitive = Cesium.createXbsjGroundPrimitive(center, this.width, this.height, this.rotation, image, color, minHeight, maxHeight, classificationType);
          var groundPrimitive = (0, _createGroundRectangle2.default)(_this.position, _this.width, _this.height,
            _this.origin[0], _this.origin[1], _this.rotation, image, color, classificationType);

          _this._texture && (groundPrimitive.appearance.material.uniforms.image = _this._texture);

          ['red', 'green', 'blue', 'alpha'].forEach(function(v, i) {
            return _this._scratchColor[v] = _this.color[i];
          });
          groundPrimitive.appearance.material.uniforms.color = _this._scratchColor;

          _this._groundPrimitive = earth.czm.scene.groundPrimitives.add(groundPrimitive);
        };

        updateGroundPrimitive();

        _this.disposers.push((0, _mobx.reaction)(function() {
          return {
            position: [].concat((0, _toConsumableArray3.default)(_this.position)),
            origin: [].concat((0, _toConsumableArray3.default)(_this.origin)),
            rotation: _this.rotation,
            width: _this.width,
            height: _this.height,
            color: [].concat((0, _toConsumableArray3.default)(_this.color))
          };
        }, updateGroundPrimitive));

        // 修复贴地面不停地更新时，不能隐藏
        var updateGroundPrimitive2 = function updateGroundPrimitive2() {
          _this._groundPrimitive && (_this._groundPrimitive.show = _this.show);
        };

        updateGroundPrimitive2();
        _this.disposers.push((0, _mobx.reaction)(function() {
          return {
            show: _this.show,
            _groundPrimitive: _this._groundPrimitive
          };
        }, updateGroundPrimitive2));

        // 这种方式没法处理crossOrigin的情况，换成Cesium的加载方式，Cesium内部会处理好Image图像的加载
        // const updateImage = () => {
        //     if (this.imageUrl) {
        //         this._myImage = this._myImage || new Image();
        //         this._myImage.src = this.imageUrl;
        //         this._myImage.onload = () => {
        //             this.canvasWidth = this._myImage.naturalWidth;
        //             this.canvasHeight = this._myImage.naturalHeight;
        //             this.drawCanvas(ctx => {
        //                 ctx.clearRect(0, 0, this._myImage.naturalWidth, this._myImage.naturalHeight);
        //                 ctx.drawImage(this._myImage, 0, 0);
        //             });
        //         }
        //     }
        // };
        var updateImage = function updateImage() {
          if (_this._imageSubscription) {
            _this._imageSubscription.unsubscribe();
            _this._imageSubscription = undefined;
          }

          if (_this.imageUrl) {
            var _observable = new rxjs.Observable(function(observer) {
              Cesium.Resource.createIfNeeded(_this.imageUrl).fetchImage().then(function(image) {
                observer.next(image);
              });
            });

            _this._imageSubscription = _observable.subscribe(function(image) {
              _this.canvasWidth = image.naturalWidth;
              _this.canvasHeight = image.naturalHeight;
              _this.drawCanvas(function(ctx) {
                ctx.clearRect(0, 0, image.naturalWidth, image.naturalHeight);
                ctx.drawImage(image, 0, 0);
              });
              _this._innerImage = image;
            });
          }
        };

        updateImage();
        _this.disposers.push((0, _mobx.reaction)(function() {
          return _this.imageUrl;
        }, updateImage));
        return _this;
      }

      (0, _createClass3.default)(CustomGroundRectangle, [{
        key: 'drawCanvas',
        value: function drawCanvas(drawFun) {
          if (this.canvasWidth > 0 && this.canvasHeight > 0) {
            drawFun(this._ctx);
            this._texture.copyFrom(this._canvas);
          } else {
            console.warn('canvas尺寸未设置，无法绘制！');
          }
        }
      }, {
        key: 'flyTo',
        value: function flyTo() {
          var radius = Math.sqrt(this.width * this.width + this.height * this.height);
          this._earth.camera.flyTo(this.position, radius * 3.0);
        }
      }]);
      return CustomGroundRectangle;
    }(_XbsjCzmObj3.default);

    var xbsjSchema = {
      title: "CustomGroundRectangle Property",
      type: "object",
      properties: {
        /**
         * 位置数组 [经度、纬度、高度] <br/>
         * @type {array}
         * @instance
         * @default [0, 0, 0]
         * @memberof Obj.CustomGroundRectangle
         */
        position: {
          type: 'array',
          items: {
            type: 'number'
          },
          minItems: 3,
          maxItems: 3,
          default: [0.0, 0.0, 0.0],
          description: '位置（经度, 纬度, 高度）'
        },
        /**
         * 原点在纹理上的位置，旋转的中心点
         * @type {array}
         * @instance
         * @default [0.5, 0.5]
         * @memberof Obj.CustomGroundRectangle
         */
        origin: {
          type: 'array',
          items: {
            type: 'number'
          },
          minItems: 2,
          maxItems: 2,
          default: [0.5, 0.5],
          description: '原点在纹理上的位置，旋转的中心点'
        },
        /**
         * 偏航角
         * @type {number}
         * @instance
         * @default 0
         * @memberof Obj.CustomGroundRectangle
         */
        rotation: {
          type: 'number',
          title: '偏航角',
          default: 0,
          description: '偏航角'
        },
        /**
         * 宽度，单位米
         * @type {number}
         * @instance
         * @default 1000
         * @memberof Obj.CustomGroundRectangle
         */
        width: {
          type: 'number',
          title: '宽度，单位米',
          default: 1000,
          description: '宽度，单位米'
        },
        /**
         * 高度，单位米
         * @type {number}
         * @instance
         * @default 1000
         * @memberof Obj.CustomGroundRectangle
         */
        height: {
          type: 'number',
          title: '高度，单位米',
          default: 1000,
          description: '高度，单位米'
        },
        /**
         * 画布宽度，单位像素
         * @type {number}
         * @instance
         * @default 512
         * @memberof Obj.CustomGroundRectangle
         */
        canvasWidth: {
          type: 'number',
          title: '画布宽度，单位像素',
          default: 512,
          description: '画布宽度，单位像素'
        },
        /**
         * 画布高度，单位像素
         * @type {number}
         * @instance
         * @default 512
         * @memberof Obj.CustomGroundRectangle
         */
        canvasHeight: {
          type: 'number',
          title: '画布高度，单位像素',
          default: 512,
          description: '画布高度，单位像素'
        },
        /**
         * 是否在三维窗口中显示
         * @type {boolean}
         * @instance
         * @default true
         * @memberof Obj.CustomGroundRectangle
         */
        show: {
          type: 'boolean',
          title: '是否在三维窗口中显示',
          default: true,
          description: '是否在三维窗口中显示'
        },
        /**
         * 颜色叠加
         * @type {array}
         * @instance
         * @default [1, 1, 1, 1]
         * @memberof Obj.CustomGroundRectangle
         */
        color: {
          type: 'array',
          items: {
            type: 'number'
          },
          minItems: 4,
          maxItems: 4,
          default: [1, 1, 1, 1],
          description: '颜色叠加'
        },
        /**
         * 纹理对应的图像url <br/>
         * 警告：一旦imageUrl有值，会导致drawCanvas调用失效！因此使用imageUrl之后，就不要再调用drawCanvas了！<br/>
         * @type {string}
         * @instance
         * @default ''
         * @memberof Obj.CustomPrimitive
         */
        imageUrl: {
          type: 'string',
          title: '纹理对应的图像url',
          default: 0,
          description: '纹理对应的图像url'
        }
      }
    };

    CustomGroundRectangle.xbsjSchema = xbsjSchema;

    var xbsjClassification = [{
      name: {
        chinese: '通用',
        english: 'General'
      },
      properties: ['position', 'origin', 'rotation', 'width', 'height', 'canvasWidth', 'canvasHeight', 'show',
        'color'
      ]
    }];

    CustomGroundRectangle.xbsjClassification = xbsjClassification;

    CustomGroundRectangle.defaultOptions = defaultOptions;
    _XbsjObject2.default.registerType(CustomGroundRectangle, 'CustomGroundRectangle');

    exports.default = CustomGroundRectangle;

    /***/
  }),
